#include "mycommon.h"
#include "oled.h"

void Cprint() {
    printf("aaa\n");
    // OLED_ShowCHinese(108, 0, 6);
    int OLEDfd = open(IIC_DEV, O_RDWR);

    int a = ioctl(OLEDfd, I2C_SLAVE, 0x3C);
    unsigned char buf[2];
    read(OLEDfd, buf, 2);

    printf("%d,%d,%02X,%02X\n", OLEDfd, a, buf[0], buf[1]);
}
// FILE* ftemp;

float getTemp() {
    FILE *f;
    char *tmp = NULL;
    float x;
    tmp = (char *)malloc(5);
    f = popen("cat /sys/class/thermal/thermal_zone0/temp","r");
    fgets(tmp,32,f);
    x = atof(tmp)/1000.0;
    printf("temp:%.2lf\n",x);
    return x;

}
int main(void)
{
    uint8_t t;
    int i = 0;
    int ret;
    Cprint();
    ret = OLED_Init(); //初始化OLED
    // getTemp_init();
    if (ret < 0)return 0;
    OLED_Clear();

    t = ' ';
    // OLED_ShowCHinese(0, 0, 0);   //中
    // OLED_ShowCHinese(18, 0, 1);  //景
    // OLED_ShowCHinese(36, 0, 2);  //园
    // OLED_ShowCHinese(54, 0, 3);  //电
    // OLED_ShowCHinese(72, 0, 4);  //子
    // OLED_ShowCHinese(90, 0, 5);  //科
    // OLED_ShowCHinese(108, 0, 6); //技
    OLED_ShowCHinese(0, 0, 0);   //中
    OLED_ShowCHinese(18, 0, 1);  //景
    OLED_ShowCHinese(36, 0, 2);  //园
    OLED_ShowCHinese(54, 0, 3);  //电
    OLED_ShowCHinese(72, 0, 4);  //子
    OLED_ShowCHinese(90, 0, 5);  //科
    OLED_ShowCHinese(108, 0, 6); //技
    float x = getTemp();
    char temp[15] = { 0 };
    sprintf(temp, "CPU: %.2lf C\n", x);
    OLED_ShowString(6, 3, temp, 16);
    //OLED_ShowString(8,2,"ZHONGJINGYUAN");
    //	OLED_ShowString(20,4,"2014/05/01");
    OLED_ShowString(0, 6, "ASCII:", 16);
    OLED_ShowString(63, 6, "CODE:", 16);

    printf("11\n");
    while (1)
    {
        x = getTemp();
        sprintf(temp, "CPU: %.2lf C\n", x);
        printf("%.2lf C\n", x);
        OLED_ShowString(6, 3, temp, 16);
        i++;
        printf("%d\n", i);
        usleep(200);
        // OLED_Clear();
        OLED_ShowChar(48, 6, t, 16); //显示ASCII字符
        t++;
        if (t > '~')
            t = ' ';
        OLED_ShowNum(103, 6, t, 3, 16); //显示ASCII字符的码值
        //     // sleep(2);
        //     // OLED_DrawBMP(0, 0, 128, 8, BMP1); //图片显示(图片显示慎用，生成的字表较大，会占用较多空间，FLASH空间8K以下慎用)
        //     // sleep(2);
        //     // OLED_DrawBMP(0, 0, 128, 8, BMP1);
        //     // sleep(2);
    }
    // OLED_Close();
    // exit(EXIT_SUCCESS);
}
